package rui.example.spring.boot.mybatis.moreDatasource.configuraion;

import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import rui.example.spring.boot.mybatis.moreDatasource.dao.master.MasterTablesMapper;

import javax.sql.DataSource;

@Configuration
@AutoConfigureAfter({MyBatisConfigurationSupport.class})
@MapperScan(basePackageClasses = {MasterTablesMapper.class},sqlSessionFactoryRef = "masterSqlSessionFactory")
public class MasterMybatisConfiguration {

    @Bean("masterSqlSessionFactory")
    @Qualifier("masterSqlSessionFactory")
    @Primary
    public SqlSessionFactory masterSqlSessionFactory(
            MybatisAutoConfiguration mybatisAutoConfiguration,
            @Qualifier("masterDataSource") DataSource masterDataSource) throws Exception {
        return mybatisAutoConfiguration.sqlSessionFactory(masterDataSource);
    }
}
